package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Plugin;
import com.ruoyi.system.service.IPluginService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 集成工具Controller
 * 
 * @author ruoyi
 * @date 2025-06-13
 */
@RestController
@RequestMapping("/system/plugin")
public class PluginController extends BaseController
{
    @Autowired
    private IPluginService pluginService;

    /**
     * 查询集成工具列表
     */
    @PreAuthorize("@ss.hasPermi('system:plugin:list')")
    @GetMapping("/list")
    public TableDataInfo list(Plugin plugin)
    {
        startPage();
        List<Plugin> list = pluginService.selectPluginList(plugin);
        return getDataTable(list);
    }

    /**
     * 导出集成工具列表
     */
    @PreAuthorize("@ss.hasPermi('system:plugin:export')")
    @Log(title = "集成工具", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Plugin plugin)
    {
        List<Plugin> list = pluginService.selectPluginList(plugin);
        ExcelUtil<Plugin> util = new ExcelUtil<Plugin>(Plugin.class);
        util.exportExcel(response, list, "集成工具数据");
    }

    /**
     * 获取集成工具详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:plugin:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pluginService.selectPluginById(id));
    }

    /**
     * 新增集成工具
     */
    @PreAuthorize("@ss.hasPermi('system:plugin:add')")
    @Log(title = "集成工具", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Plugin plugin)
    {
        return toAjax(pluginService.insertPlugin(plugin));
    }

    /**
     * 修改集成工具
     */
    @PreAuthorize("@ss.hasPermi('system:plugin:edit')")
    @Log(title = "集成工具", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Plugin plugin)
    {
        return toAjax(pluginService.updatePlugin(plugin));
    }

    /**
     * 删除集成工具
     */
    @PreAuthorize("@ss.hasPermi('system:plugin:remove')")
    @Log(title = "集成工具", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pluginService.deletePluginByIds(ids));
    }
}
